<?php
defined('IN_ADMIN') or exit('No permission resources.');
$show_validator = $show_scroll = $show_dialog = 1;
include $this->admin_tpl('header','admin');
?>
<script type="text/javascript">
<!--
	$(function(){
		$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'200',height:'50'}, function(){this.close();$(obj).focus();})}});
		$("#name").formValidator({onshow:"<?php echo L("input").L('variable_name')?>",onfocus:"<?php echo L("input").L('variable_name')?>",oncorrect:"<?php echo L('input_right');?>"}).inputValidator({min:1,onerror:"<?php echo L("input").L('variable_name')?>"});
		$("#value").formValidator({onshow:"<?php echo L("input").L('variable_value')?>",onfocus:"<?php echo L("input").L('variable_value')?>",oncorrect:"<?php echo L('input_right');?>"}).inputValidator({min:1,onerror:"<?php echo L("input").L('variable_value')?>"});
	})
//-->
</script>
<div class="pad-lr-10">
<form action="?m=variable&c=manage&a=add" method="post" id="myform">
<fieldset>
	<legend><?php echo L('variable_info')?></legend>
	<table width="100%"  class="table_form">
  <tr>
    <th width="120"><?php echo L('variable_name')?>：</th>
    <td class="y-bg"><input type="text" id="name" class="input-text" name="info[name]" size="30" /></td>
  </tr>
  <tr>
    <th><?php echo L('variable_desc')?>：</th>
    <td class="y-bg">
    	<textarea rows="4" cols="29" name="info[description]" id="description"></textarea>
    </td>
  </tr>
    <tr>
      <th><?php echo L('variable_value')?>：</th>
      <td class="y-bg">
		<textarea placeholder="多个值请用英文逗号隔开" rows="4" cols="29" name="info[value]" id="value"></textarea>
      </td>
    </tr>
    <tr>
    	<th><?php echo L('variable_color')?>：</th>
    	<td class="y-bg">
			<?php echo form::radio($this->color,0,'name="variable_color" class="color_select"');?>
     	</td>
    </tr>
    <tr>
    	<th><?php echo L('variable_view')?>：</th>
    	<td id="color_view"></td>
    </tr>
    <tr>
      <th><?php echo L('variable_sort')?>：</th>
      <td class="y-bg">
		<input type="text" id="listorder" class="input-text" name="info[listorder]" size="30" value="0"/>
      </td>
    </tr>
</table>
</fieldset>
<div class="bk15"></div>
    <input type="submit" class="dialog" id="dosubmit" name="dosubmit" value="<?php echo L('submit');?>" />
</form>
</div>
<script type="text/javascript">
<!--
$(".color_select").click(function(){
	var color = $(this).val();
	var variable_value = $("#value").val();
	if(variable_value.length>0){
		console.log(variable_value);
		console.log(variable_value.indexOf('_'));
		if(variable_value.indexOf('_')>0){
			var s = variable_value.split(',');
			var s_value=""
			for(var i=0;i<s.length;i++){
				s_value += s[i].substring(0,s[i].length-8)+'_'+color+',';
			}
		} else {
			var s = variable_value.split(',');
			var s_value=""
			for(var i=0;i<s.length;i++){
				s_value += s[i]+'_'+color+',';
			}
		}
// 		console.log();
		$("#value").val(s_value.substring(0,s_value.length-1));
	}
	$("#color_view").css("background",color);
	});
//-->
</script>
</body>
</html>
